/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.miracleteam.miracle.dao.daoImpl;

import com.miracleteam.miracle.dao.TinhThanhDAO;
import com.miracleteam.miracle.entities.Tinhthanh;
import com.miracleteam.miracle.utils.HibernateUtil;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author DangKhoa
 */
public class TinhThanhDAOImpl implements TinhThanhDAO{
    Logger logger= Logger.getLogger(TinhThanhDAOImpl.class);
    public List LayDanhSachTinhThanh() {
         List ds = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
           
            String hql = "From Tinhthanh where DaXoa = 0";
            Query query = session.createQuery(hql).setCacheable(true);
            ds = query.list();

        } catch (Exception e) {
            logger.error(e.getMessage());
            System.out.println(e.getMessage());
        }
        finally{
            session.close();
        }
        return ds;
    }
    public Tinhthanh LayTinhThanh(String ma) {
        Tinhthanh tt = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            String hql = "From Tinhthanh where DaXoa=0 AND maTinhThanh=:maTT";
            Query query = session.createQuery(hql);
            query.setString("maTT", ma);
            Object ob = query.uniqueResult();
            tt =  (Tinhthanh)ob;
        } catch (HibernateException e) {
             logger.error(e.getMessage());
        } finally {
            session.close();
        }
        return tt;
    }
    
}
